package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Collect;
import cn.wolfcode.trip.base.mapper.CollectMapper;
import cn.wolfcode.trip.base.query.CollectQueryObject;
import cn.wolfcode.trip.base.service.ICollectService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/collects")
public class CollectController {

    @Autowired
    private ICollectService collectService;


    //获取当前的收藏量和点赞量
    @GetMapping
    public Map get(Collect collect){
        Map map = collectService.get(collect);
        return map;
    }
    //修改当前收藏的收藏量和点赞数
    @PutMapping
    public JsonResult put(Collect collect){
        JsonResult result = new JsonResult();
        try {
            collectService.save(collect);
        } catch (Exception e) {

            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
    @PostMapping("/views")
    public void addViews(Collect collect){

        collectService.updataViews(collect);
    }

    //获取当前的收藏
    @GetMapping("/content")
    public PageInfo lists(CollectQueryObject qo){
        return collectService.query(qo);
    }

}
